<?php

namespace App\Http\Models;

use Illuminate\Support\Facades\Redis;

class TokenModel
{
	
	const PREFIX_KEY = 'token:';
	const EXPIRES_TIME = '604800';

    // set token
	public static function set_token($token, $id)
	{
		$redis = Redis::connection('db_main');
		return $redis->setex(self::PREFIX_KEY . $token, self::EXPIRES_TIME, $id);
	}

	// get token
	public static function get_token($token)
	{
		$redis = Redis::connection('db_main_slave');
		return $redis->get(self::PREFIX_KEY . $token);
	}

	// delete token
	public static function del_token($token)
	{
		$redis = Redis::connection('db_main');
		return $redis->del(self::PREFIX_KEY . $token);
	}
}

